package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.ITMSWebService;

import java.util.HashMap;
import java.util.Map;

/**
 * ITMS_WebService_Imp_startGetUserInfoDiag
 * ITMS-用户信息查询
 * @author xuzhi
 *
 */
public class ITMS_WebService_Imp_startGetUserInfoDiag implements WorkInterFace {

	@Override
	public String getName() {
		return "ITMS-用户信息查询";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[3];
		in[0]=new Attr("ppp_usename","用户宽带账号(三个参数选填一个)",AttrType.TYPE_String,true);
		in[1]=new Attr("serial_number","设备序列号(三个参数选填一个)",AttrType.TYPE_String,true);
		in[2]=new Attr("logic_id","终端SN号(三个参数选填一个)",AttrType.TYPE_String,true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[13];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("return", "返回return", AttrType.TYPE_String, true);
		out[2]=new Attr("op_id", "操作流水号,操作唯一标识号", AttrType.TYPE_String, true);
		out[3]=new Attr("result", "0——成功；-1——不存在用户（无法查到用户）；-10——平台异常或繁忙", AttrType.TYPE_String, true);
		out[4]=new Attr("logic_id", "用户loid", AttrType.TYPE_String, true);
		out[5]=new Attr("ppp_usename", "用户宽带账号", AttrType.TYPE_String, true);
		out[6]=new Attr("serial_number", "终端SN", AttrType.TYPE_String, true);
		out[7]=new Attr("ppp_password", "用户宽带密码", AttrType.TYPE_String, true);
		out[8]=new Attr("customer_id", "客户号", AttrType.TYPE_String, true);
		out[9]=new Attr("auth_username", "用户voip账号", AttrType.TYPE_String, true);
		out[10]=new Attr("err_msg", "出错原因描述", AttrType.TYPE_String, true);
		out[11]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[12]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		ITMSWebService webService=new ITMSWebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setFunctionName("startGetUserInfoDiag");
		attrsIn.setRequestMessage("<op_id>"+webService.getop_id()+"</op_id>" +
	            "<logic_id>"+webService.dealString((String) data.get("logic_id"))+"</logic_id>" +
	            "<ppp_usename>"+webService.dealString((String) data.get("ppp_usename"))+"</ppp_usename>" +
	            "<customer_id></customer_id>" +
	            "<serial_number>"+webService.dealString((String) data.get("serial_number"))+"</serial_number>"+
	            "<auth_username></auth_username>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn,1);
		String flag=webService.getPattern("return", returnXml);
		
		if(flag.length()>0){
				map.put("ReturnCode", 0);
				map.put("return", webService.getPattern("return", returnXml));
				map.put("op_id", webService.getPattern("op_id", returnXml));
				map.put("result", webService.getPattern("result", returnXml));
				map.put("logic_id", webService.getPattern("logic_id", returnXml));
				map.put("ppp_usename", webService.getPattern("ppp_usename", returnXml));
				map.put("serial_number", webService.getPattern("serial_number", returnXml));
				map.put("ppp_password", webService.getPattern("ppp_password", returnXml));
				map.put("customer_id", webService.getPattern("customer_id", returnXml));
				map.put("auth_username", webService.getPattern("auth_username", returnXml));
				map.put("err_msg", webService.getPattern("err_msg", returnXml));
				map.put("log", returnXml);
				map.put("Errormsg", "");
			}else{
				map.put("ReturnCode", 1);
				map.put("return", "");
				map.put("op_id", "");
				map.put("result", "");
				map.put("logic_id", "");
				map.put("ppp_usename", "");
				map.put("serial_number", "");
				map.put("ppp_password", "");
				map.put("customer_id", "");
				map.put("auth_username", "");
				map.put("err_msg", "");
				map.put("log", returnXml);
				map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
